import Mock from 'mockjs' 

const login = function(option){ 
  console.log(option.body)
  let obj = JSON.parse(option.body)
  if(obj.username==='admin'&& obj.password==='123'){
    return {
      data:{
        status: 200,
        token: "96e2eb7dc7772e777c634243ff3e9272ad4b6b78"
      }
    }
  }
  return {
    data:{
      msg:'username password error'
    }
  }
}

const getUser = function(option){ 
  console.log(option.body)
  return {
    data:{
      name:'piggy',
      age:28,
    }
  }
}

const updatePassword = function(option){ 
  console.log(option.body)
  return {
    data:{
      result:'success',
      code:200,
    }
  }
}

const menuList = function(option){ 
  console.log(option.body)
  let obj = JSON.parse(option.body)
  if(obj.token==="96e2eb7dc7772e777c634243ff3e9272ad4b6b78"){
    return {
      data:{
        result:[
          {
            'label':'首页管理',
            'name':'admin',
            'icon':'Document',
            'child':[
                {
                  'label':'首页管理',
                  'name':'first',
                  'icon':'Document',
                  'path':'/first'
                }
            ]
          },
          {
            'label':'信息管理',
            'name':'pictureAdmin',
            'icon':'Document',
            'child':[
                {
                  'label':'信息管理',
                  'name':'message',
                  'icon':'Location',
                  'path':'/message',
                }
            ]
          },
          {
            'label':'用户管理',
            'name':'userAdmin',
            'icon':'Location',
            'child':[
                {
                  'label':'用户管理',
                  'name':'userHome',
                  'icon':'Location',
                  'path':'/goods/list'
                },
                {
                  'label':'会员等级',
                  'name':'userRank',
                  'icon':'Location',
                  'path':'/goods/list'
                }
            ]
          }
      ],
        code:200,
      }
    }
  }else{
    return {
      data:{
        code:200,
        result:[]
      }
    }
  }

}

const userList = function(){ 
  return {
    data:{
      result:[
        {
          date: '2016-05-03',
          name: 'Tom',
          address: 'No. 189, Grove St, Los Angeles',
        },
        {
          date: '2016-05-02',
          name: 'John',
          address: 'No. 189, Grove St, Los Angeles',
        },
        {
          date: '2016-05-04',
          name: 'Morgan',
          address: 'No. 189, Grove St, Los Angeles',
        },
        {
          date: '2016-05-01',
          name: 'Jessy',
          address: 'No. 189, Grove St, Los Angeles',
        },
      ],
      code:200,
    }
  }
}

Mock.mock('/admin/login', /post|get/i, login)
Mock.mock('/admin/getUser', /post|get/i, getUser)
Mock.mock('/admin/updatePassword', /post|get/i, updatePassword)
Mock.mock('/admin/userList', /post|get/i, userList)
Mock.mock('/admin/menuList', /post|get/i, menuList)